
import { Balance } from "../../model/Balance"
import { Product } from '../../model/Product'
import { Order } from '../../model/Order';

Page({

  //页面的初始数据
  data: {
    active: 0,
    goodsList: [],
    go: "",
    activeNames: ['1'],
    allPropor: [],
    todayPropor: [],
    storeList:[],
    store_id:'',
    money:0.00
  },

  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },

  //生命周期函数--监听页面加载
  onLoad: async function (options) {
    //获取 商品列表
    let result = await Product.get_product_list(wx.getStorageSync('distributor'));
    if (result.code == 0) {
      this.setData({
        goodsList: result.data,
        store_id: wx.getStorageSync('store_id')
      })
    } else {
      console.log(result);
    }
    this.propor();
    this.todayPropor();
    this.onGetStoreList();
  },

  //生命周期函数--监听页面显示
  onShow: async function() {
    this.setData({
      money:wx.getStorageSync('Bmoney')
    })
    //获取会员余额
    let balance = await Balance.get_user_balance();
    this.money(balance);
  },

  //获取名店列表
  onGetStoreList: async function () { 
    //获取 门店列表
    let result = await Product.get_store_list();
    if(result.code == 0){
      this.setData({
        storeList:result.data
      })
    }else{
      console.log(result);
    }
  },

  //全部收益
  propor: async function () {
    //获取 核销员业绩统计
    let result = await Order.get_distributor_statistics(wx.getStorageSync('distributor'),'all');
    if (result.code == 0) {
      this.setData({
        allPropor: result.data
      })
    } else {
      console.log(result);
    }
  },

  // 今日收益
  todayPropor: async function () {
    //获取 核销员业绩统计
    let result = await Order.get_distributor_statistics(wx.getStorageSync('distributor'),'today');
    if (result.code == 0) {
      this.setData({
        todayPropor: result.data
      })
    } else {
      console.log(result);
    }
  },

  //  可提现余额
  money(balance) {
    this.setData({
      money:balance.data.balance
    })
    wx.setStorageSync('Bmoney', balance.data.balance)
    wx.setStorageSync('Bicon', balance.data.balance_icon)
  },

  poster: function (e) {
    wx.navigateTo({
      url: '/pages/poster/index?id=' + e.currentTarget.dataset.id,
    })
  },

  splist: function (e) {
    console.log(e.currentTarget.dataset);
    wx.navigateTo({
      url: '/pages/splitsale_sale/index?id=' + e.currentTarget.dataset.id + "&name=" + e.currentTarget.dataset.name + "&price=" + e.currentTarget.dataset.price + "&bfbind=" + e.currentTarget.dataset.bfbind + "&make=" + 0,
    })
  },

  cardlist: function (e) {
    wx.navigateTo({
      url: '/pages/splitsale_sale/index?id=' + e.currentTarget.dataset.id + "&name=" + e.currentTarget.dataset.name + "&price=" + e.currentTarget.dataset.price + "&bfbind=" + e.currentTarget.dataset.bfbind + "&make=" + 20,
    })
  },

  //店铺推广
  storego: function () {
    wx.navigateTo({
      url: '/pages/splitsale_sale/index?make=' + 1,
    })
  },

  //店铺海报
  ShopPoster: function () {
    wx.navigateTo({
      url: '/pages/poster/index?id=' + (-1),
    })
  },

  onShareAppMessage: function (e) {
    console.log(e);
    if(e.target.dataset.make == 1){ //店铺推广
      return {
        title: '送自己与闺蜜花之盛宴',
        path: '/pages/home/index?scene=' + wx.getStorageSync("user_id")+","+ wx.getStorageSync("store_id")+","+wx.getStorageSync("store_id")+",1",
        imageUrl: 'https://img01.yzcdn.cn/upload_files/2021/05/03/Fi6DGCCc5i5Y2x3eeZxY2wQlWUEp.png'
      }
    }else if(e.target.dataset.make  == 20){
      return {
        title: '送自己与闺蜜花之盛宴',
        path: '/pages/cardbuy/index?scene='+wx.getStorageSync('user_id')+','+this.data.id,//?scene='+wx.getStorageSync('user_id')+'&id='+this.data.id
        imageUrl: 'https://img01.yzcdn.cn/upload_files/2021/05/03/Fi6DGCCc5i5Y2x3eeZxY2wQlWUEp.png'
      }
    }else{//商品推广
      return {
        title: '送自己与闺蜜花之盛宴',
        path: '/pages/register/index?scene=' + wx.getStorageSync("user_id")+","+ wx.getStorageSync("store_id")+","+this.data.id+",0",
        imageUrl: 'https://img01.yzcdn.cn/upload_files/2021/05/03/Fi6DGCCc5i5Y2x3eeZxY2wQlWUEp.png'
      }
    }
  }

})